package com.huyun.web.FutureTest;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

/**
 * @program:
 * @description:
 * @author: hyq
 * @create: 2021-12-30 14:42
 */
public class ThenApplyTest {

    /**
     * thenApply转换：：将前面计算结果的的CompletableFuture传递给thenApply，
     * 返回thenApply处理后的结果。可以认为通过thenApply方法实现CompletableFuture<T>至CompletableFuture<U>的转换。
     * 白话一点就是将CompletableFuture的计算结果作为thenApply方法的参数，返回thenApply方法处理后的结果
     */
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        //这里将前一个CompletableFuture计算出来的结果扩大八倍
        CompletableFuture<Integer> result = CompletableFuture.supplyAsync(ThenApplyTest::randomInteger).thenApply((i) -> i * 8);
        System.out.println(result.get());
    }

    public static Integer randomInteger() {
        return 10;
    }
}
